/**
 * 
 */
package any.desktop.server;

import java.util.HashMap;
import java.util.Map;

import org.lpny.groovyrestlet.GroovyRestlet;
import org.restlet.Component;
import org.restlet.data.Protocol;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * TODO: Doc me
 * 
 * @author keke <keke@codehaus.org>
 * @version
 * @revision $Revision:$
 */
public class Lanucher {

    /**
     * @param args
     * @throws Exception
     */
    public static void main(final String[] args) throws Exception {
        final ApplicationContext ctx = new ClassPathXmlApplicationContext(
                new String[] { "meta-inf/appAll.xml" });
        ((ClassPathXmlApplicationContext) ctx).registerShutdownHook();

        final GroovyRestlet gr = new GroovyRestlet(ctx);
        final Map<String, Object> binding = new HashMap<String, Object>();
        binding.put("appRoot", "/any/desktop/api");
        binding.put("gwtRoot", "/any/desktop");
        binding.put("tagApp", "/any/tag/api");
        final Component component = (Component) gr.build(binding, Thread
                .currentThread().getContextClassLoader().getResource(
                        "desktop.groovy").toURI());
        Runtime.getRuntime().removeShutdownHook(new Thread() {

            @Override
            public void run() {
                try {
                    component.stop();
                } catch (final Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        component.getServers().add(Protocol.HTTP, 8182);
        component.start();
    }

}
